#pragma once 
#include <iostream>
using namespace std;
#include <pthread.h>

class Mutex
{
public:
    Mutex(){
        int n = pthread_mutex_init(&_mutex,nullptr);
        (void)n;
    }
    void Lock(){
        int n = pthread_mutex_lock(&_mutex);
        (void)n;
    }
    void Unlock(){
        int n = pthread_mutex_unlock(&_mutex);
        (void)n;
    }
    ~Mutex(){
        int n = pthread_mutex_destroy(&_mutex);
        (void)n;
    }
private:
    Mutex(const Mutex& m) = delete;
    Mutex& operator=(const Mutex&m) = delete;
    pthread_mutex_t _mutex;
};

class LockGuard
{
public:
    LockGuard(Mutex& mutex) :_mutex(mutex){
        _mutex.Lock();
    }
    ~LockGuard(){
        _mutex.Unlock();
    }
private:
    Mutex& _mutex;
};